<template>
    恭喜您成功登录：您的个人信息是{{ username }}
</template>

<script>
import { mapState } from 'vuex'
export default {
    name: 'P1',
    data() {
        return {
            form: {
                username: '',
                password: '',
                token: ''
            }
        }
    },
    computed: {
        ...mapState(['username']),
    },
    mounted() {
        this.loadData();
    },
    methods: {
        async loadData() {
            this.form.username = this.username;
            try {
                const username = this.form.username;
                const response = await fetch(`http://localhost:3000/api/auth/user?username=${encodeURIComponent(username)}`, {
                    method: 'GET',
                    headers: {
                        'Content-Type': 'application/json'
                    }
                });
                const data = await response.json();
                console.log(data);
                if (!response.ok) {
                    throw new Error(data.message || '获取个人信息失败');
                }
            } catch (error) {
                console.error('Error:', error);
            }
            return data
        },
    }
}
</script>